{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
	<form class="layui-form gg-form-bar border-x" lay-filter="barsearchform" id="barsearchform">
<!--		<div class="layui-input-inline" style="width:150px;">-->
<!--			<select name="type">-->
<!--				<option value="">选择审批类别</option>-->
<!--				{volist name="type" id="vo"}-->
<!--				<option value="{$vo.id}">{$vo.title}</option>-->
<!--				{/volist}-->
<!--			</select>-->
<!--		</div>-->
		<div class="layui-input-inline" style="width:150px;">
			<input type="text" name="username"  placeholder="选择申请人" class="layui-input picker-one" readonly>
			<input type="text" name="uid" value="" style="display:none" />	
			<input type="text" name="status" value="0" style="display:none" />	
		</div>
<!--		<div class="layui-input-inline" style="width:300px;">-->
<!--			<select name="type" ></select>-->
<!--		</div>-->
		<div class="layui-input-inline" style="width:300px;">
			<select name="check_status" id="">
				<option value="">状态</option>
				{foreach ['草稿','审核中','已通过','已拒绝','已撤销'] as $k=>$v}
				<option value="{$k}">{$v}</option>
				{/foreach}
			</select>
		</div>
		<div class="layui-input-inline" style="width:150px;">
			<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
			<button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
		</div>
	</form>
	<table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
	<a href="javascript:" class="layui-btn layui-btn-normal" lay-event="plTg">批量通过</a>
	<a href="javascript:" class="layui-btn layui-btn-danger" lay-event="pljj">批量拒绝</a>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','employeepicker','laydatePlus'];
	function gouguInit() {
		var form = layui.form,table = layui.table, tool = layui.tool ,element=layui.element,laydatePlus = layui.laydatePlus;
		  
		//日期范围
		var apply_time = new laydatePlus({'target':'apply_time'});

		layui.laydate.render({
			elem:"#bTime"
		})
		layui.laydate.render({
			elem:"#eTime"
		})
		element.on('tab(tab)', function(data){
			$("#barsearchform")[0].reset();
			layui.pageTable.reload({where:{status:data.index},page:{curr:1}});
			$('[name="status"]').val(data.index);
			return false;
		});	
			
		//监听搜索提交
		form.on('submit(webform)', function(data) {
			layui.pageTable.reload({
				where: data.field,
				page: {curr: 1}
			});
			return false;
		});
		$('[lay-filter="clear"]').on('click',function(){
			setTimeout(function(){
				$('[lay-filter="webform"]').click();
			},10)			
		});
			
		layui.pageTable = table.render({
			elem: '#test'
			,toolbar: '#toolbarDemo'
			,defaultToolbar: false
			,title:'审批列表'
			,url: "{:url('')}"
			,page: true //开启分页
			,limit: 20
			,cellMinWidth: 80
			,cols: [[
				{type: 'checkbox', fixed: 'left' },
					{field:'id',width:80, title: 'ID号', align:'center'}
					,{field:'createUser',title: '申请人',align:'center'}
					,{field:'spTitle',title: '审批类型',align:'center'}
					// ,{field:'create_time',title: '申请时间',width:132,align:'center',templet:function (d) {
					// 	return d.create_time ? formatTimeTwo(d.create_time) : "-"
					// }}
					// ,{field:'start_time',title: '出差开始时间',width:100, align:'center',templet:function (d) {
					// 	return d.start_time ? formatTimeTwo(d.start_time,'Y-M-D') : "-"
					// }}
					// ,{field:'end_time',title: '出差结束时间',width:100,align:'center',templet:function (d) {
					// 	return d.end_time ? formatTimeTwo(d.end_time,'Y-M-D') : "-"
					// }}
					// ,{field:'address',title: '出差地址',width:120,align:'center'}
					// ,{field:'content',title: '理由/说明/备注'}
					// ,{field:'pName',title: '关联项目'}
					,{field:'check_status', title: '状态',align:'center',templet: function(d){
						var htmlArray = ['<span style="color:#666666">待审批</span>','<span style="color:#4285f4">审批中</span>','<span style="color:#34a853">已通过</span>','<span style="color:#FF5722">已拒绝</span>','<span style="color:#fbbc05">已撤销</span>'];
						return htmlArray[d.check_status];
					}}
					,{width:60,fixed: 'right',title: '操作', align:'center',templet: function(d){
						var btn='<a class="layui-btn layui-btn-xs" lay-event="view">详情</a>';
						return btn;
					}}
				]]
			});
			
			table.on('tool(test)',function (obj) {
				if(obj.event === 'view'){
					tool.side("{:url('view')}?id="+obj.data.id);
				}
			});
		table.on('toolbar(test)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
			console.log(checkStatus)
			switch(obj.event){
				case 'plTg':
					var data = checkStatus.data;
					var ids=[]
						var ischecked=[];
					if (data.length){
						data.forEach(function (value,index) {
							if (value.check_status>1){
								ischecked.push(value.id)
							}
							ids.push(value.id)
						})
						if (ischecked.length){
							layer.msg('已审批数据不可重复审批');
							return;
						}
						layer.prompt({
							title: '审批意见',
							formType: 0
						}, function(val, index){

							if (val==''){
								layer.msg('请输入审批意见');
								return;
							}
							layer.close(index);
							let param={
								id:ids.join(','),
								type:1,
								check:1,
								check_node:0,
								check_admin_ids:0,
								content:val
							};
							 httpRequest("{:url('/api/index/flow_check')}",param,function (res) {
							 	console.log('res',res)
							 	if (res.code==0){
									layui.pageTable.reload();
								}
							 })
						});

					}else {
						layer.msg('请选择数据');
					}
					break;
				case 'pljj':
					var data = checkStatus.data;
					var ids=[]
					var ischecked=[];
					if (data.length){
						data.forEach(function (value,index) {
							if (value.check_status>1){
								ischecked.push(value.id)
							}
							ids.push(value.id)
						})
						if (ischecked.length){
							layer.msg('已审批数据不可重复审批');
							return;
						}
						layer.prompt({
							title: '审批意见',
							formType: 0
						}, function(val, index){

							if (val==''){
								layer.msg('请输入审批意见');
								return;
							}
							layer.close(index);
							let param={
								id:ids.join(','),
								type:1,
								check:2,
								check_node:0,
								check_admin_ids:0,
								content:val
							};
							httpRequest("{:url('/api/index/flow_check')}",param,function (res) {
								console.log('res',res)
								if (res.code==0){
									layui.pageTable.reload();
								}
							})
						});

					}else {
						layer.msg('请选择数据');
					}

					break;

			};
		})
		}
	</script>
{/block}
<!-- /脚本 -->